<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
.fixed-table-footer {    background-color: #dad6d63d;}
.myerror{color:#f00;font-size:14px;margin-left:5px;font-weight: bold;}
.pdef{border: 0px;font-size: 18px;    width: 50px;    color: #f00;}
table {table-layout:fixed;} th, td{word-break:break-all;}  .fixed-table-container thead th .th-inner{ white-space:normal; }
</style>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse" style="text-align: center;">
			<b style="font-size: 20px;">《[[${paperdef.name}]]》考试已设定</b>
			（卷面总分：<input class="pdef" id="totalScore" type="text" th:value="${paperdef.totalScore}" readonly="true" />
			及格分：<input class="pdef" type="text" th:value="${paperdef.passScore}" readonly="true" />
			考试时长：<input class="pdef" type="text" th:value="${paperdef.duration}" readonly="true" />分钟）
			<b style="font-size: 20px;color:#f00;">组卷须符合要求!!!</b>
			</div>
			<div class="col-sm-12 search-collapse" style="text-align: center;">
			<b style="font-size: 20px;">目前已设置</b>
			（卷面总分：<a class="btn btn-warning btn-xs " id="mytotalScore" href="#" >0</a>
			题量：<a class="btn btn-info btn-xs " id="myqnum" href="#" >0</a>）
			<label id="score-error" class="myerror" ></label>
			</div>
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="exam:papertpl:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="exam:papertpl:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="exam:papertpl:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "exam/papertpl";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/"+[[${paperdef.id}]],
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                modalName: "试卷模板",
                queryParams:{"ksid":[[${paperdef.id}]]},
				search: false,
		        showExport: true,
		        showFooter:true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '编号'
				},
				/* {
					field : 'ksid', 
					title : '考试任务id'
				}, */
				{
					field : 'qdb.name', 
					title : '题库'
				},
				{
					field : 'qdbkb.name', 
					title : '知识点'
				},
				{
					field : 'qtype.name', 
					title : '题型'
				},
				{
					field : 'qteasy', 
					title : '难易度',
					footerFormatter: function (value) {
						//return "<b>合计：</b>";
					}
				},
				{
					field : 'score', 
					title : '分值',
					footerFormatter: function (value) { 
						var count = 0; 
						for (var i in value) { 
							count += value[i].score*value[i].qnum; 
						} 
						$("#mytotalScore").text(count);
						if(count>$("#totalScore").val()){
							//$.modal.alertWarning("试卷模板合计分数【"+count+"】不能超过考试设定的分数【"+$("#totalScore").val()+"】");
							$("#mytotalScore").removeClass("btn-warning").removeClass("btn-success").addClass("btn-danger");
							$("#score-error").html("目前设置的卷面总分【超过】考试设定的卷面总分");
							//return '<a class="btn btn-danger btn-xs " href="#" >'+count+'</a> ';
						}
						else if(count==$("#totalScore").val()){
							$("#score-error").html("");
							$("#mytotalScore").removeClass("btn-warning").removeClass("btn-danger").addClass("btn-success");
							//return '<a class="btn btn-success btn-xs " href="#" >'+count+'</a> ';
						}else{
							$("#score-error").html("目前设置的卷面总分【小于】考试设定的卷面总分");
							$("#mytotalScore").removeClass("btn-danger").removeClass("btn-success").addClass("btn-warning");
							//return '<a class="btn btn-warning btn-xs " href="#" >'+count+'</a> ';
						}
					}
				},
				{
					field : 'qnum', 
					title : '题量',
					footerFormatter: function (value) { 
						var count = 0; 
						for (var i in value) { 
							count += value[i].qnum; 
						} 
						$("#myqnum").text(count);
						//return '<a class="btn btn-info btn-xs " href="#" >'+count+'</a> ';
					}
				},
				{
					field : 'qids', 
					title : '圈定题目',
					width:400
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs " href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>